package com.baomidou.springwind.cms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.kisso.annotation.Permission;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springwind.cms.entity.CmsLink;
import com.baomidou.springwind.cms.service.ICmsLinkService;
import com.baomidou.springwind.sys.controller.BaseController;

/**
 * <p>
 * 角色管理相关操作
 * </p>
 *
 *
 * @Author hubin
 * @Date 2016-04-15
 */
@Controller
@RequestMapping("/cms/link")
public class CmsLinkController extends BaseController {

	@Autowired
	private ICmsLinkService cmsLinkService;
	
	@Permission("2002")
	@RequestMapping("/list")
	public String list( Model model ) {
		return "/cms/list";
	}


	@ResponseBody
	@Permission("2002")
	@RequestMapping("/getLinkList")
	public String getLinkList() {
		Page<CmsLink> page = getPage();
		return jsonPage(cmsLinkService.selectPage(page, null));
	}


	@ResponseBody
	@Permission("2003")
	@RequestMapping("/delete/{id}")
	public String delete( @PathVariable Long id ) {
		return booleanToString(cmsLinkService.deleteById(id));
	}


	@Permission("2002")
	@RequestMapping("/edit")
	public String edit( Model model, Long id ) {
		if ( id != null ) {
			model.addAttribute("link", cmsLinkService.selectById(id));
		}
		return "/link/edit";
	}


	@ResponseBody
	@Permission("2002")
	@RequestMapping("/editLink")
	public String editLink( CmsLink link ) {
		boolean rlt = false;
		if ( link != null ) {
			if ( link.getId() != null ) {
				rlt = cmsLinkService.updateById(link);
			} else {
				rlt = cmsLinkService.insertSelective(link);
			}
		}
		return callbackSuccess(rlt);
	}


	
}
